/**
 *    @file       classfactory.cpp
 *
 *    @brief      
 *    @details
 *
 *    @version    1.0
 *    @date       02/10/2014 05:39:08 PM
 *
 *    @author     Theophilus (), wangtf418@gmail.com
 */
#include "classfactory.h"
#include "maintainthread.h"
#include "timerthread.h"

#include "maintainudptask.h"

#include "maintaincmd.h"

classfactory::classfactory()
{

}

classfactory::~classfactory()
{

}

workthread * classfactory::gen_workthread(bf_uint32_t type, bf_uint32_t size, bf_uint32_t index, const comargs *args)
{
	workthread *thread = NULL;
	switch (type)
	{
		case THD_TYPE_TIMER:
			{
				thread = new timerthread(type, size, index, args);
				break;
			}
		case THD_TYPE_MAINTAIN:
			{
				thread = new maintainthread(type, size, index, args);
				break;
			}
		default:
			{
				break;
			}
	}
	return thread;
}

sockettask * classfactory::gen_sockettask(bf_uint32_t type, csocket *sock, netprocessthread *netthread, const comargs *args /* = NULL */)
{
	sockettask *task = NULL;
	switch (type)
	{
		case TSK_TYPE_MAINTAIN_UDP:
			{
				task = new maintainudptask(sock, netthread, args);
				break;
			}
		default:
			{
				break;
			}
	}
	return task;
}

command * classfactory::gen_command(bf_char_t *buf, bf_size_t buflen)
{
	command *cmd = NULL;
	if (!buf || buflen == 0)
	{
		return cmd;
	}
	//process
	//...
	return cmd;
}

command * classfactory::gen_maintain_command(bf_char_t *buf, bf_size_t buflen)
{
	command *cmd = NULL;
	if (!buf || buflen == 0)
	{
		return cmd;
	}
	bf_int_t cmdid = maintain_cmdhead::get_cmdid(buf, buflen);
	if (cmdid < 0)
	{
		return cmd;
	}
	switch (cmdid)
	{
		case MAINTAIN_CMD_TYPE_LOGSWITCH:
			{
				cmd = new logswitchcmd(buf, buflen);
				break;
			}
		default:
			{
				break;
			}
	}
	return cmd;
}



